<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!--1.引入vue框架-->
    <script src="../5.19/vue.js"></script>
</head>
<body>
    <!--2.定义根目录标签-->
    <div id="app">
        <button @click="add">添加学生</button>
        <button @click="del">删除学生</button>
        <table border="1" width="50%" style="border-collapse: collapse;">
            <thead>
                <th>班级</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
            </thead>
            <tbody>
                <tr align="center" v-for="item in stuList">
                    <td>{{item.grade}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.gender}}</td>
                    <td>{{item.age}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
<script>
    //3.创建vue对象
    var vm=new Vue({
        el:"#app",
        data:{
            stuList:[
                {grade:2105,name:"宋江",gender:"男",age:23},
                {grade:2105,name:"宋江",gender:"男",age:23},
                {grade:2105,name:"宋江",gender:"男",age:23},
                {grade:2105,name:"宋江",gender:"男",age:23},
                {grade:2105,name:"宋江",gender:"男",age:23}
            ]
        },
        methods:{
            add(){
                console.log("进入添加学生方法");
                var stu={
                    grade:2105,name:"林冲",gender:"女",age:32
                };
                this.$data.stuList.push(stu);
            },
            del(){
                console.log("进入删除方法");
                this.$data.stuList.pop();
            }
        }
    })
</script>
</html>